package com.yogee.topseller.activity.tianyan;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.yogee.core.http.listener.HttpOnNextListener;
import com.yogee.core.http.subscribers.BaseSubscriber;
import com.yogee.core.utils.ToastUtils;
import com.yogee.topseller.R;
import com.yogee.topseller.activity.base.HttpActivity;
import com.yogee.topseller.adapter.BzxrAdapter;
import com.yogee.topseller.adapter.GbbdAdapter;
import com.yogee.topseller.adapter.GbjgAdapter;
import com.yogee.topseller.adapter.GpfhAdapter;
import com.yogee.topseller.adapter.JyycAdapter;
import com.yogee.topseller.adapter.SxrAdapter;
import com.yogee.topseller.adapter.YzwfAdapter;
import com.yogee.topseller.bean.BzxrBean;
import com.yogee.topseller.bean.GbbdBean;
import com.yogee.topseller.bean.GbjgBean;
import com.yogee.topseller.bean.GpfhBean;
import com.yogee.topseller.bean.JyycBean;
import com.yogee.topseller.bean.SxrBean;
import com.yogee.topseller.bean.YzwfBean;
import com.yogee.topseller.http.HttpManager;
import com.yogee.topseller.layout.TitleLayout;
import com.yogee.topseller.utils.AppUtil;
import com.yogee.topseller.utils.Constants;
import com.yogee.topseller.view.EmptyRecyclerView;

import java.util.List;

import butterknife.BindView;

public class BzxrDetailActivity extends HttpActivity {

    @BindView(R.id.add_card_titlelayout)
    TitleLayout titlelayout;
    @BindView(R.id.rv_detail)
    EmptyRecyclerView rv_detail;
    @BindView(R.id.id_empty_view)
    View id_empty_view;
    @BindView(R.id.iv_empty)
    ImageView iv_empty;

    BzxrAdapter detailAdapter = null;
    GbjgAdapter gbjgAdapter = null;
    GpfhAdapter gpfhAdapter = null;
    GbbdAdapter gbbdAdapter = null;
    SxrAdapter sxrAdapter = null;
    YzwfAdapter yzwfAdapter = null;
    JyycAdapter jyycAdapter = null;

    private String type = "";
    private String companyId="";
    private String cmpanyType = "";
    private String proId = "";
    @Override
    protected int getLayoutId() {
        return R.layout.activity_detail_bzxr;
    }

    @Override
    protected void initView() {
        titlelayout.setActivity(this);
        titlelayout.setTitle(getIntent().getStringExtra("title"));
        type =  getIntent().getStringExtra("type");
        companyId = getIntent().getStringExtra("companyId");
        cmpanyType = getIntent().getStringExtra("cmpanyType");
        proId = getIntent().getStringExtra("proId");
        rv_detail.setLayoutManager(new LinearLayoutManager(this));
        iv_empty.setImageResource(R.drawable.nodata1);
        rv_detail.setEmptyView(id_empty_view);
        if(type.equals(Constants.EyeCheck_BZXR_TYPE)){
            detailAdapter = new BzxrAdapter(this);
            rv_detail.setAdapter(detailAdapter);
//            detailAdapter.addData((List<BzxrBean.Item>) getIntent().getSerializableExtra("info"));
            initBzxr();

        }else if(type.equals(Constants.EyeCheck_GBJG_TYPE)){
            gbjgAdapter = new GbjgAdapter(this);
            rv_detail.setAdapter(gbjgAdapter);
            initGbjg();
            // 股票分红
        }else if(type.equals(Constants.EyeCheck_GPFH_TYPE)){
            gpfhAdapter = new GpfhAdapter(this);
            rv_detail.setAdapter(gpfhAdapter);
//            gpfhAdapter.addData((List<GpfhBean.Item>) getIntent().getSerializableExtra("info"));
            initGpfh();

        }else if(type.equals(Constants.EyeCheck_GBBD_TYPE)){
            gbbdAdapter = new GbbdAdapter(this);
            rv_detail.setAdapter(gbbdAdapter);
//            gbbdAdapter.addData((List<GbbdBean.Item>) getIntent().getSerializableExtra("info"));
            initGbbd();

        }else if(type.equals(Constants.EyeCheck_SXR_TYPE)){
            sxrAdapter = new SxrAdapter(this);
            rv_detail.setAdapter(sxrAdapter);
//            sxrAdapter.addData((List<SxrBean.Item>) getIntent().getSerializableExtra("info"));
            initSxr();

        }else if(type.equals(Constants.EyeCheck_YZWF_TYPE)){
            yzwfAdapter = new YzwfAdapter(this);
            rv_detail.setAdapter(yzwfAdapter);
//            yzwfAdapter.addData((List<YzwfBean.Item>) getIntent().getSerializableExtra("info"));
            initYzwf();

        }else if(type.equals(Constants.EyeCheck_JYYC_TYPE)){
            jyycAdapter = new JyycAdapter(this);
            rv_detail.setAdapter(jyycAdapter);
//            jyycAdapter.addData((List<JyycBean.Item>) getIntent().getSerializableExtra("info"));
            initJyyc();
        }


    }

    private void initBzxr(){
        HttpManager.getInstance().eyeCheckBzxr(companyId,type, AppUtil.getUserId(BzxrDetailActivity.this),cmpanyType,proId).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<BzxrBean>() {
            @Override
            public void onNext(BzxrBean o) {
                if(o.getEyeCheck().getError_code()==0){
                    detailAdapter.addData(o.getEyeCheck().getResult().getItems());
                }else{
//                    ToastUtils.showToast(BzxrDetailActivity.this,o.getEyeCheck().getReason());
                }

            }
        }, this));
    }


    private void initGbjg(){
        HttpManager.getInstance().eyeCheckGBJG(companyId,type, AppUtil.getUserId(BzxrDetailActivity.this),cmpanyType,proId).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<GbjgBean>() {
            @Override
            public void onNext(GbjgBean o) {
                if(o.getEyeCheck().getError_code()==0){
                    gbjgAdapter.addData(o.getEyeCheck().getResult().getDataList());
                }else{
//                    ToastUtils.showToast(BzxrDetailActivity.this,o.getEyeCheck().getReason());
                }

            }
        }, this));
    }


    private void initGpfh(){
        HttpManager.getInstance().eyeCheckGPFH(companyId,type, AppUtil.getUserId(BzxrDetailActivity.this),cmpanyType,proId).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<GpfhBean>() {
            @Override
            public void onNext(GpfhBean o) {
                if(o.getEyeCheck().getError_code()==0){
                    gpfhAdapter.addData(o.getEyeCheck().getResult().getItems());
                }else{
//                    ToastUtils.showToast(BzxrDetailActivity.this,o.getEyeCheck().getReason());
                }
            }
        }, this));
    }


    private void initGbbd(){
        HttpManager.getInstance().eyeCheckGBBD(companyId,type, AppUtil.getUserId(BzxrDetailActivity.this),cmpanyType,proId).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<GbbdBean>() {
            @Override
            public void onNext(GbbdBean o) {
                if(o.getEyeCheck().getError_code()==0){
                    gbbdAdapter.addData(o.getEyeCheck().getResult().getItems());
                }else{
//                    ToastUtils.showToast(BzxrDetailActivity.this,o.getEyeCheck().getReason());
                }

            }
        }, this));
    }

    private void initSxr(){
        HttpManager.getInstance().eyeCheckSXR(companyId,type, AppUtil.getUserId(BzxrDetailActivity.this),cmpanyType,proId).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<SxrBean>() {
            @Override
            public void onNext(SxrBean o) {
                if(o.getEyeCheck().getError_code()==0){
                    sxrAdapter.addData(o.getEyeCheck().getResult().getItems());
                }else{
//                    ToastUtils.showToast(BzxrDetailActivity.this,o.getEyeCheck().getReason());
                }

            }
        }, this));
    }

    /**
     * 严重违法
     */
    private void initYzwf(){
        HttpManager.getInstance().eyeCheckYzwf(companyId,type, AppUtil.getUserId(BzxrDetailActivity.this),cmpanyType,proId).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<YzwfBean>() {
            @Override
            public void onNext(YzwfBean o) {
                if(o.getEyeCheck().getError_code()==0){
                    yzwfAdapter.addData(o.getEyeCheck().getResult().getItems());
                }else{
//                    ToastUtils.showToast(BzxrDetailActivity.this,o.getEyeCheck().getReason());
                }

            }
        }, this));
    }
    /**
     * 经营异常
     */
    private void initJyyc(){
        HttpManager.getInstance().eyeCheckJyyc(companyId,type, AppUtil.getUserId(BzxrDetailActivity.this),cmpanyType,proId).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<JyycBean>() {
            @Override
            public void onNext(JyycBean o) {
                if(o.getEyeCheck().getError_code()==0){
                    jyycAdapter.addData(o.getEyeCheck().getResult().getItems());
                }else{
//                    ToastUtils.showToast(BzxrDetailActivity.this,o.getEyeCheck().getReason());
                }

            }
        }, this));
    }

}
